import axios from '@/utils/request'
export default {
  Staff: {
    list: {
      export: {
        query: {
          '@display': `{
            'id' : 'entity.getId()',
            'user' : 'entity.getUser().__toString()',
            'store' : 'entity.getStore().__toString()',
            'squad' : 'entity.getSquad().__toString()',
            'team' : 'entity.getSquad().getTeam().__toString()',
            'name' : 'entity.getName()',
            'balance' : 'entity.getUser().getBalance().getAmount()',
            'role' : 'entity.getRole().__toString()',
            'phone' : 'entity.getPhone()',
            'enabled': 'entity.getEnabled() <= 0 ? "离职" : "在职"',
            'realname': 'entity.getUser().getProfile().getRealname() != null ? entity.getUser().getProfile().getRealname() : "无"',
            'idCardNumber': 'entity.getUser().getProfile().getIdCardNumber() != null ? entity.getUser().getProfile().getIdCardNumber() : "无"',
            'collector' : 'entity.getCollector().__toString()'
          }`,
          limit: 10000000
        },
        label: {
          'id': '工号',
          'user': '绑定用户',
          'store': '门店',
          'squad': '小队',
          'team': '团队',
          'name': '姓名',
          'balance': '账号余额',
          'role': '角色',
          'phone': '电话',
          'enabled': '状态',
          'realname': '实名',
          'idCardNumber': '身份证',
          'collector': '代收人'
        }
      },
      query: {
        '@expands': "['entity.user.balance']"
      },
      disabled_actions: ['new'],
      list_filter: {
        id: {
          expression: 'entity.getId() == ":value"',
          label: 'id',
          type: 'input'
        },
        'phone': '电话',
        'store.id': () => {
          return axios
            .get(`/manage/stores`)
            .then(res =>
              Object.assign({ __label: '门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        'squad.id': () => {
          return axios
            .get(`/manage/squads`)
            .then(res =>
              Object.assign({ __label: '小队' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        'squad.team.id': () => {
          return axios
            .get(`/manage/teams`)
            .then(res =>
              Object.assign({ __label: '团队' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        name: {
          expression: `entity.getName() matches ":value"`,
          label: '名称',
          type: 'input'
        },
        enabled: {
          expression: 'entity.getEnabled() :value 0',
          label: '状态',
          data: [
            { value: '>', label: '在职' },
            { value: '==', label: '离职' }
          ]
        },
        startTime: {
          expression: `
          entity.getCreatedTime() >= datetime.get(":value")
        `,
          label: '注册开始时间',
          type: 'datetime'
        },
        endTime: {
          expression: `
          entity.getCreatedTime() < datetime.get(":value")
        `,
          label: '注册开始时间',
          type: 'datetime'
        },
      },
      list_display: [
        'id',
        'user',
        'store',
        { property: 'squad', label: '小队' },
        'name',
        { property: 'user.__metadata.balance.__metadata.amount', label: '余额' },
        { property: 'role', label: '角色' },
        'phone',
        { property: 'collector', label: '业绩代收账号' },
        { property: 'dailyWage', label: '日薪', editable: true },
        { property: 'divideToLeader', label: '日薪队长抽金额', editable: true },
        { property: 'divideToBroker', label: '日薪经纪抽金额', editable: true },
        { property: 'qrRegistration', label: '扫码注册', type: 'boolean' },
        { property: 'isManager', editable: true },
        { property: 'canMakeOrder', label: '是否下单', editable: true },
        { property: 'enabled', label: '是否在职', editable: true }
      ]
    },
    form: {
      fields: [
        'store',
        { property: 'user' },
        'phone',
        'name',
        { property: 'squad', field_options: { label: '小队' }, required: false },
        { property: 'role', field_options: { label: '角色' } },
        {
          property: 'collector',
          field_options: {
            label: '业绩代收账号'
          },
          required: false,
          help: '设置了代收账号，这个员工在本场所/门店产生的所有收入将自动划分到代收账号上面'
        },
        { property: 'dailyWage', field_options: { label: '日薪' } },
        {
          property: 'divideToLeader',
          field_options: { label: '日薪队长抽佣' },
          help: '发日薪时候队长抽佣金额，'
        },
        {
          property: 'divideToBroker',
          field_options: { label: '日薪经纪抽佣' },
          help: '发日薪时候经纪抽佣金额，'
        },
        'isManager',
        { property: 'enabled', field_options: { label: '是否在职' }, default_value: true },
        'extraData',
        { property: 'monthlyInsurance', required: false }
      ]
    }
  }
}

